{%TEMPLATE->struct/head%}
{%TEMPLATE->struct/menu%}
<h2>Agents ([[numAgents]])</h2>
{%TEMPLATE->struct/messages%}
<div class="card">
  <div class="table-responsive">
    <table class="table table-bordered table-sm" id="agents">
      <thead>
        <tr>
          <th>Id</th>
          <th>Act</th>
          <th>Name / Owner / Client</th>
          <th>GPUs/CPUs</th>
          <th>CPU only</th>
          <th>Last activity</th>
          <th>Access Groups</th>
          <th>Action</th>
        </tr>
      </thead>
      <tbody>
        {{FOREACH agent;[[agents]]}}
          <tr>
            <td><a href="agents.php?id=[[agent.getId()]]">[[agent.getId()]]</a></td>
            <td data-sort="[[agent.getIsActive()]]">
              <form id="active[[agent.getId()]]" action="agents.php" method="post">
                <input type='hidden' name='action' value='[[$DAgentAction::SET_ACTIVE]]'>
                <input type="hidden" name="agentId" value="[[agent.getId()]]">
                <input type="hidden" name="csrf" value="[[csrf]]">
                <input type="checkbox" {{IF [[agent.getIsActive()]] == 1}} checked{{ENDIF}} {{IF [[agent.getUserId()]] != [[login.getUserId()]] && ![[accessControl.hasPermission([[$DAccessControl::MANAGE_AGENT_ACCESS]])]]}}disabled{{ENDIF}} onChange="document.getElementById('active[[agent.getId()]]').submit();" title="Is Active">
              </form>
            </td>
            <td data-sort="[[agent.getAgentName()]]">
              <a href="agents.php?id=[[agent.getId()]]">[[agent.getAgentName()]]</a>
              {{IF [[agent.getIsTrusted()]] == 1}}
                <span class="fas fa-lock" aria-hidden="true"></span>
              {{ENDIF}}
              {{IF [[agent.getIsActive()]] == 0}}
                <span class="fas fa-pause-circle" aria-hidden="true"></span>
              {{ENDIF}}
              <br>
              {{IF [[agent.getUserId()]] > 0}}
                [[Util::getUsernameById([[agent.getUserId()]])]]
              {{ELSE}}
                ---
              {{ENDIF}}
              {{IF strlen([[agent.getClientSignature()]]) > 0}}
                <br>Running: [[agent.getClientSignature()]]
              {{ELSE}}
                <br>Running: unknown
              {{ENDIF}}
            </td>
            <td>
              [[str_replace("\n","<br>",[[agent.getDevices()]])]]
            </td>
            <td>
              {{IF [[agent.getCpuOnly()]] == 0}}
                No
              {{ELSE}}
                Yes
              {{ENDIF}}
            </td>
            <td>
              <code>[[agent.getLastAct()]]</code> at <br>
              [[date([[config.getVal(DConfig::TIME_FORMAT)]], [[agent.getLastTime()]])]]<br>
              IP:
              {{IF [[config.getVal([[$DConfig::HIDE_IP_INFO]])]] == 0}}
                <code>[[agent.getLastIp()]]</code>
              {{ELSE}}
                <code>Hidden</code>
              {{ENDIF}}
            </td>
            <td>
              {{FOREACH accessGroup;[[accessGroupAgents.getVal([[agent.getId()]])]]}}
                [[accessGroup.getGroupName()]]<br>
              {{ENDFOREACH}}
            </td>
            {{IF [[accessControl.hasPermission([[$DAccessControl::MANAGE_AGENT_ACCESS]])]]}}
              <td>
                <form action="agents.php" method="POST" class="float-right" onSubmit="if (!confirm('Really delete agent [[agent.getId()]]?')) return false;">
                  <input type='hidden' name='action' value='[[$DAgentAction::DELETE_AGENT]]'>
                  <input type="hidden" name="agentId" value="[[agent.getId()]]">
                  <input type="hidden" name="csrf" value="[[csrf]]">
                  <button type="submit" class='btn btn-danger' data-toggle="tooltip" data-placement="top" title="Delete"><i class="fas fa-trash" aria-hidden="true"></i></button>
                </form>
              </td>
            {{ELSE}}
              <td>&nbsp;</td>
            {{ENDIF}}
          </tr>
        {{ENDFOREACH}}
      </tbody>
    </table>
    <script type="text/javascript">
      $(document).ready(function () {
        $('#agents').DataTable({
          pageLength: 50,
          "order": [ [0, 'asc'] ],
          "columnDefs": [
            { "orderable": false, "targets": [5, 7] },
            { "orderable": true, "targets": [0, 1, 2, 3, 4, 6] }
          ]
        });
      });
    </script>
  </div>
</div>
{%TEMPLATE->struct/foot%}
